package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-18
 * Time: 19:35
 */
public enum TestEnum {
    RED("hong", 0.1),BLACK("hei", 1.5),GREEN("lv", 2.6);//枚举对象

    @Override
    public String toString() {
        return "TestEnum{" +
                "color='" + color + '\'' +
                ", ordinal=" + ordinal +
                '}';
    }

    public String color;
    public double ordinal;
    //枚举的构造方法 默认是私有的
    TestEnum(String name, double o) {
        color = name;
        ordinal = o;
    }

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + " " + testEnums[i].ordinal());
        }

        TestEnum testEnum = TestEnum.valueOf("RED");
        System.out.println(testEnum);

        System.out.println(BLACK.compareTo(RED));
    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                System.out.println("wrong");
                break;
        }
    }
}
